package com.hmall.search.web;

import com.hmall.common.dto.PageDTO;
import com.hmall.search.pojo.ItemDoc;
import com.hmall.search.pojo.RequestParams;
import com.hmall.search.service.ISearchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/search")
public class SearchController {

    @Autowired
    private ISearchService searchService;

    @GetMapping("hello")
    public String hello(){
        return "hello";
    }

    /**
     * 搜索栏自动补全功能
     * @param prefix
     * @return
     */
    @GetMapping("/suggestion")
    public List<String> getSuggestion(@RequestParam("key") String prefix) {
        return searchService.getSuggestion(prefix);
    }

    /**
     * 过滤项聚合功能
     * @param params
     * @return
     */
    @PostMapping("filters")
    public Map<String, List<String>> getFilters(@RequestBody RequestParams params) {
        return searchService.filters(params);
    }

    /**
     * 实现基本搜索功能
     *
     * @param params
     * @return
     */
    @PostMapping("/list")
    public PageDTO<ItemDoc> searchList(@RequestBody RequestParams params) {
        return searchService.searchList(params);
    }
}
